<?php
use yii\helpers\Html;
use kartik\form\ActiveForm;
use common\widgets\cover_upload\CoverUpload;
use kartik\select2\Select2;
use admin\models\db\Categories;
use common\components\wtools\tools\ArrayHelper;
use kartik\datetime\DateTimePicker;

/* @var $this yii\web\View */
/* @var $model admin\modules\product\models\forms\Products */
/* @var $form \kartik\form\ActiveForm */

$categoryList = Categories::find()->all();
$categoryList = ArrayHelper::map($categoryList, 'id', 'name');
?>

<div class="products-form">
    <?php $form = ActiveForm::begin(); ?>
    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
    <?= $form->field($model, 'cover')->widget(CoverUpload::className(), [
        'defaultCoverUrl' => Yii::$app->urlManagerXcxApi->createAbsoluteUrl(['/guest/pub/gd', 'w' => 300, 'h' => 300]),
        'coverWidth' => 300,
        'uploadUrl' => Yii::$app->urlManager->createAbsoluteUrl(['/pub/ajax/upload-cover']),
        'options' => [
            'class' => 'form-control url-cover'
        ],
    ])?>
    <?= $form->field($model, 'cate_root')->widget(Select2::classname(), [
        'data' => $categoryList,
        'options' => [
            'placeholder' => '请选择',
        ],
        'pluginOptions' => [
            'allowClear' => true
        ]
    ]) ?>
    <?php $form->field($model, 'sheff_on_at')->widget(DateTimePicker::className(), [
        'options' => [
            'class' => "form-control",
            'autocomplete' => "off",
        ],
    ]) ?>
    <?php $form->field($model, 'sheff_off_at')->widget(DateTimePicker::className(), [
        'options' => [
            'class' => "form-control",
            'autocomplete' => "off",
        ],
    ]) ?>
    <?= $form->field($model, 'status')->dropDownList($model::getStatusDesc()) ?>
    <?= $form->field($model, 'product_sort')->textInput() ?>

	<?php if (!Yii::$app->request->isAjax){ ?>
	  	<div class="form-group">
	        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', '新建') : Yii::t('app', '更新'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
	    </div>
	<?php } ?>
    <?php ActiveForm::end(); ?>
</div>
